package ro.tm.uvt.lp.raccoon.screens;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable;

import ro.tm.uvt.lp.raccoon.catchGame.screens.RaccoonGameScreen;
import ro.tm.uvt.lp.raccoon.collectorGame.CollectorGameScreen;
import ro.tm.uvt.lp.raccoon.SaveTheRaccoon;


public class MainMenuScreen implements Screen {

    private SaveTheRaccoon game;
    private Stage stage;
    private ImageButton playCatch;
    private ImageButton playCollector;

    public MainMenuScreen(Game g){
        game=(SaveTheRaccoon)g;
        stage = new Stage();
        Gdx.input.setInputProcessor(stage);
        Skin skin=new Skin(Gdx.files.internal("uiskin.json"));

        Image background =new Image( new Texture(Gdx.files.internal("raccoonBack.png")));
        stage.addActor(background);

        playCatch = new ImageButton(new SpriteDrawable(new Sprite(new Texture(Gdx.files.internal("playCatch.png")))),
                new SpriteDrawable(new Sprite(new Texture(Gdx.files.internal("playCatch_ON.png")))));
        playCatch.setPosition(74, 240);
        playCatch.setSize(320, 72);
        playCatch.addListener(new ClickListener() {
            @Override
            public void touchUp(InputEvent e, float x, float y, int point, int button) {
                startGame();
            }
        });


        playCollector = new ImageButton(new SpriteDrawable(new Sprite(new Texture(Gdx.files.internal("playCollector.png")))),
                new SpriteDrawable(new Sprite(new Texture(Gdx.files.internal("playCollector_ON.png")))));
        playCollector.setPosition(74, 160);
        playCollector.setSize(320, 72);
        playCollector.addListener(new ClickListener() {
            @Override
            public void touchUp(InputEvent e, float x, float y, int point, int button) {
                startGameOld();
            }
        });


        stage.addActor(playCatch);
        stage.addActor(playCollector);
    }

    private void startGameOld(){
        game.setScreen(new CollectorGameScreen(game));
    }

    private void startGame(){game.setScreen(new RaccoonGameScreen(game));}

    @Override
    public void show() {

    }

    @Override
    public void render(float delta) {
        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        stage.act(delta);
        stage.draw();
    }

    @Override
    public void resize(int width, int height) {

    }

    @Override
    public void pause() {

    }

    @Override
    public void resume() {

    }

    @Override
    public void hide() {

    }

    @Override
    public void dispose() {

    }
}
